//
//  HLRecomandCell.m
//  HLAerospace
//
//  Created by hulian-ios on 17/9/11.
//  Copyright © 2017年 hulian-LB. All rights reserved.
//

#import "HLRecomandCell.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/UIImageView+WebCache.h>
#import "HLCourseRecommand.h"

@interface HLRecomandCell()

/** iconView  */
@property (nonatomic ,strong) UIImageView *iconView;
/** numButton  */
@property (nonatomic ,strong) UIButton *numButton;
/** title  */
@property (nonatomic ,strong) UILabel *title;


@end

@implementation HLRecomandCell

- (UIImageView *)iconView
{
    if (!_iconView ) {
        _iconView = [[UIImageView alloc] init];
        _iconView.layer.cornerRadius = 3;
        _iconView.clipsToBounds = YES;
    }
    return _iconView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = HLRGB(245, 245, 245);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUI];
    }
    return self;
}

- (UILabel *)title
{
    if (!_title ) {
        _title = [[UILabel alloc] init];
        _title.backgroundColor = [UIColor clearColor];
        _title.textColor = HLRGB(60, 60, 60);
        _title.font = [UIFont systemFontOfSize:IS_IPHONE_5 ? 12: kMainTitleFontSize];
    }
    return _title;
}

- (UIButton *)numButton
{
    if (!_numButton) {
        _numButton = [[UIButton alloc]init];
        _numButton.userInteractionEnabled = NO;
        _numButton.titleLabel.font = [UIFont systemFontOfSize:IS_IPHONE_5 ? 10: 12];
        _numButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -10);
        [_numButton setImage:[UIImage imageNamed:@"home_course_play_num"] forState:UIControlStateNormal];
        [_numButton sizeToFit];
        [_numButton setTitle:@"181.3万" forState:UIControlStateNormal];
        [_numButton setTitleColor:HLRGB(120, 120, 120) forState:UIControlStateNormal];
        
    }
    return _numButton;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}


- (void)setUI
{
    [self.contentView addSubview:self.iconView];
    [self.contentView addSubview:self.title];
    [self.contentView addSubview:self.numButton];

}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self configsCons];
}

- (void)configsCons
{
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.top.equalTo(self.contentView).offset(5);
        make.bottom.equalTo(self.contentView).offset(-5);
        make.width.equalTo(@(self.contentView.width * 0.4));
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(10);
        make.top.equalTo(self.contentView).offset(5);
        make.height.equalTo(@(45));
        make.right.equalTo(self.contentView).offset(-10);
    }];
    
    [self.numButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(10);
        make.top.equalTo(self.title.mas_bottom);
        make.height.equalTo(@(45));
    }];
 
}


- (void)setCourseRecommand:(HLCourseRecommand *)courseRecommand
{
    _courseRecommand = courseRecommand;
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:courseRecommand.course_pic] placeholderImage:nil];
    self.title.text = courseRecommand.course_name;
}


@end
